package com.jxc.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jxc.VO.UserVO;
import com.jxc.mapper.UserMapper;
import com.jxc.pojo.User;
import com.jxc.pojo.UserExample;
import com.jxc.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;
    @Override
    public PageInfo<UserVO> selectByExample(String userName, Integer page, Integer rows) {
        UserExample userExample = new UserExample();
        if(userName != null && userName != "") {
            userExample.createCriteria().andUserNameEqualTo(userName);
        }
        //分页
        PageHelper.startPage(page,rows);
        List<UserVO> userVOS = userMapper.selectByExample(userExample);
        PageInfo<UserVO> pageInfo = new PageInfo<>(userVOS);

        return pageInfo;
    }

    @Override
    public int saveinsert(User record) {
        return userMapper.insert(record);
    }

    @Override
    public int updateByPrimaryKeySelective(User record) {
        return userMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public List<User> findUsersName(String trueName) {
        return userMapper.findUsersName(trueName);
    }

    @Override
    public int deleteByExample(Integer uid) {
        UserExample userExample = new UserExample();
        userExample.createCriteria().andIdNotEqualTo(uid);
        System.out.println(userExample);
        return userMapper.deleteByExample(userExample);
    }

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return userMapper.deleteByPrimaryKey(id);
    }
}
